//
//  HJDLoginViewController.m
//  JYHospital
//
//  Created by 胡金东 on 16/6/1.
//  Copyright © 2016年 胡金东. All rights reserved.
//

//#import "NSString+HJDMD5.h"
#import <CommonCrypto/CommonDigest.h>

#import "HJDLoginViewController.h"
#import "HJDResigesViewController.h"
#import "HJDForgetViewController.h"
#import "AFNetworking.h"
#import "MBProgressHUD.h"
#import "HJDRootTool.h"
#import "HJDNavigationController.h"
#import "HJDPesonalCenterViewController.h"
#import "HJDTabBarController.h"
#import "RESideMenu.h"
#import "BSMacros.h"





@interface HJDLoginViewController ()<UIScrollViewDelegate,NSCoding>

@property (nonatomic,strong)  UIView *backgroundView;
@property (nonatomic,strong) UITextField  *phoneField ;

@property (nonatomic,strong)  UITextField  *passwordtextField ;

@property (nonatomic,strong) NSArray * mapArray;

@property (nonatomic,strong)UIScrollView *scroll;

@property (nonatomic,strong) UIImageView *iagView;

@property (nonatomic,strong) UIView *viewPhone;

@property (nonatomic,strong) UIView *viewPass;







@end

@implementation HJDLoginViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setUpTextFile];
    [self setupBtn];
    //添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
    tap.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tap];
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(popToPre) image:@"︿" HighImage:nil];
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardShow) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardHide) name:UIKeyboardWillHideNotification object:nil];

    
}


//返回
-(void)popToPre
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
//隐藏键盘
-(void)viewTapped:(UITapGestureRecognizer*)tap
{
    
    [self.view endEditing:YES];
    
}

-(NSString *)md5:(NSString *)str
{
    const char *cStr = [str UTF8String];
    unsigned char result[16];
    CC_MD5(cStr, strlen(cStr), result);
    NSMutableString *hash = [NSMutableString string];
    for (int i = 0; i < 16; i++)
    {
        [hash appendFormat:@"%02X", result[i]];
    }
    return [hash lowercaseString];
}


-(void)setUpTextFile
{
    self.scroll = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.scroll.delegate = self;
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.scroll.showsVerticalScrollIndicator = YES;//垂直移动
    self.scroll.showsHorizontalScrollIndicator = NO;//水平移动
    //上下滑动
    self.scroll.contentSize = CGSizeMake(HJDWidth,855 ) ;
    
    
    [self.view addSubview: self.scroll];
    
    self.backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, HJDWidth, HJDHeight- 50)];
    self.backgroundView.backgroundColor = [UIColor getColorWithHexNumber:@"F6F6F6"];
    [self.view addSubview:self.backgroundView];
    
    CGFloat loginImageX = IS_IPHONE_5?(HJDWidth-152)/2:IS_IPHONE_6?(HJDWidth-152)/2:IS_IPHONE_6_PLUS?(HJDWidth-228)/2:(HJDWidth-152)/2;
    CGFloat loginImageY = HJDVerticalMargin * 2;
    CGFloat loginImageW = IS_IPHONE_5?152:IS_IPHONE_6?152:IS_IPHONE_6_PLUS?228:152;
    CGFloat loginImageH = IS_IPHONE_5?178:IS_IPHONE_6?178:IS_IPHONE_6_PLUS?274.5:178;
    self.iagView = [[UIImageView alloc]initWithFrame:CGRectMake(loginImageX, loginImageY, loginImageW, loginImageH)];
    self.iagView.image = [UIImage imageNamed:@"登录头像"];
    [self.backgroundView addSubview:self.iagView];
    
    CGFloat phoneX = 46;
    CGFloat phoneY = IS_IPHONE_5?300:IS_IPHONE_6?350:IS_IPHONE_6_PLUS?450:230;
    CGFloat phoneW = HJDWidth - 46*2;
    CGFloat phoneH = 40;
    self.phoneField = [[UITextField alloc]initWithFrame:CGRectMake(phoneX, phoneY, phoneW, phoneH)];
    self.phoneField.placeholder = @"请输入本人手机号";
     [self.phoneField setValue:[UIFont systemFontOfSize:18] forKeyPath:@"_placeholderLabel.font"];
    [self.phoneField setValue:[UIColor getColorWithHexNumber:@"B3B3B3"] forKeyPath:@"_placeholderLabel.textColor"];
    self.phoneField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 25,phoneH )];
    self.phoneField.leftViewMode = UITextFieldViewModeAlways;
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 10, 21, 21)];
    image.image = [UIImage imageNamed:@"手机号"];
    self.phoneField.clearButtonMode = UITextFieldViewModeAlways;
    self.phoneField.keyboardType = UIKeyboardTypeNumberPad;
    [self.phoneField.leftView addSubview:image];
    
    [self.view addSubview:self.phoneField];
    
    //    横线
    CGFloat viewX = 46 ;
    CGFloat viewY = CGRectGetMaxY(self.phoneField.frame);
    CGFloat viewW = phoneW;
    CGFloat viewH = 1;
    self.viewPhone = [[UIView alloc]initWithFrame:CGRectMake(viewX, viewY, viewW, viewH)];
    self.viewPhone.backgroundColor = [UIColor getColorWithHexNumber:@"B3B3B3"];
    [self.view addSubview:self.viewPhone];
    
    CGFloat passwordX = 46  ;
    CGFloat passwordY = CGRectGetMaxY(self.viewPhone.frame) + HJDVerticalMargin;
    CGFloat passwordW = phoneW;
    CGFloat passwordH = phoneH;
    self.passwordtextField = [[UITextField alloc]initWithFrame:CGRectMake(passwordX, passwordY,passwordW, passwordH)];
    self.passwordtextField.placeholder = @"请输入密码";
    [self.passwordtextField setValue:[UIFont systemFontOfSize:18] forKeyPath:@"_placeholderLabel.font"];
    [self.passwordtextField setValue:[UIColor getColorWithHexNumber:@"B3B3B3"] forKeyPath:@"_placeholderLabel.textColor"];
    self.passwordtextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 25,phoneH )];
    self.passwordtextField.leftViewMode = UITextFieldViewModeAlways;
    UIImageView *passimage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 8, 16, 21)];
    passimage.image = [UIImage imageNamed:@"密码"];
    self.passwordtextField.clearButtonMode = UITextFieldViewModeAlways;
     self.passwordtextField.secureTextEntry = YES;
    [self.passwordtextField.leftView addSubview:passimage];
    [self.passwordtextField addTarget:self action:@selector(textPassChange) forControlEvents:UIControlEventEditingChanged];
    
    [self.view addSubview:self.passwordtextField];
    //    横线
    CGFloat passwordviewX = 46 ;
    CGFloat passwordviewY = CGRectGetMaxY(self.passwordtextField.frame);
    CGFloat passwordviewW = phoneW;
    CGFloat passwordviewH = 1;
    self.viewPass = [[UIView alloc]initWithFrame:CGRectMake(passwordviewX, passwordviewY, passwordviewW, passwordviewH)];
   
    self.viewPass.backgroundColor = [UIColor getColorWithHexNumber:@"B3B3B3"];
    [self.view addSubview:self.viewPass];
    
    CGFloat loginbtnX = 46;
    CGFloat loginbtnY = CGRectGetMaxY(self.viewPass.frame) + 38;
    CGFloat loginbtnW = phoneW;
    CGFloat loginbtnH = 50;
    
    UIButton *loginbtn = [[UIButton alloc]initWithFrame:CGRectMake(loginbtnX, loginbtnY, loginbtnW, loginbtnH)];
    [loginbtn setTitle:@"登录" forState:UIControlStateNormal];
    loginbtn.titleLabel.font = [UIFont systemFontOfSize:19];
    [loginbtn setRadius:10 borderWith:0 borderColor:nil];
    [loginbtn setBackgroundColor:[UIColor getColorWithHexNumber:@"5CC6AC"]];
    [loginbtn addTarget:self action:@selector(loginbtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginbtn];

}

-(void)keyboardShow{
    CGFloat loginImageX = IS_IPHONE_5?(HJDWidth-152)/2:IS_IPHONE_6?(HJDWidth-152)/2:IS_IPHONE_6_PLUS?(HJDWidth-228)/2:(HJDWidth-152)/2;
    CGFloat loginImageY = -100;
    CGFloat loginImageW = IS_IPHONE_5?152:IS_IPHONE_6?152:IS_IPHONE_6_PLUS?228:152;
    CGFloat loginImageH = IS_IPHONE_5?178:IS_IPHONE_6?178:IS_IPHONE_6_PLUS?274.5:178;
    self.iagView.frame = CGRectMake(loginImageX, loginImageY, loginImageW, loginImageH);
    
    CGFloat phoneX = 46;
    CGFloat phoneY = IS_IPHONE_5?220:IS_IPHONE_6?270:IS_IPHONE_6_PLUS?370:150;
    CGFloat phoneW = HJDWidth - 46*2;
    CGFloat phoneH = 40;
    self.phoneField.frame = CGRectMake(phoneX, phoneY, phoneW, phoneH);
    
    CGFloat viewX = 46 ;
    CGFloat viewY = CGRectGetMaxY(self.phoneField.frame);
    CGFloat viewW = phoneW;
    CGFloat viewH = 1;
    self.viewPhone.frame = CGRectMake(viewX,viewY, viewW, viewH);
    
    CGFloat passwordX = 46  ;
    CGFloat passwordY = CGRectGetMaxY(self.phoneField.frame)+HJDVerticalMargin;
    CGFloat passwordW = phoneW;
    CGFloat passwordH = phoneH;
    self.passwordtextField.frame = CGRectMake(passwordX, passwordY, passwordW, passwordH);
    
    CGFloat passwordviewX = 46 ;
    CGFloat passwordviewY = CGRectGetMaxY(self.passwordtextField.frame);
    CGFloat passwordviewW = phoneW;
    CGFloat passwordviewH = 1;
    self.viewPass.frame = CGRectMake(passwordviewX, passwordviewY, passwordviewW, passwordviewH);
}

-(void)keyboardHide{
    [UIView animateWithDuration:0.25 animations:^{
        
        CGFloat loginImageX = IS_IPHONE_5?(HJDWidth-152)/2:IS_IPHONE_6?(HJDWidth-152)/2:IS_IPHONE_6_PLUS?(HJDWidth-228)/2:(HJDWidth-152)/2;
        CGFloat loginImageY = HJDVerticalMargin * 2;
        CGFloat loginImageW = IS_IPHONE_5?152:IS_IPHONE_6?152:IS_IPHONE_6_PLUS?228:152;
        CGFloat loginImageH = IS_IPHONE_5?178:IS_IPHONE_6?178:IS_IPHONE_6_PLUS?274.5:178;
        self.iagView.frame = CGRectMake(loginImageX, loginImageY, loginImageW, loginImageH);

        
        CGFloat phoneX = 46;
        CGFloat phoneY = IS_IPHONE_5?300:IS_IPHONE_6?350:IS_IPHONE_6_PLUS?450:230;
        CGFloat phoneW = HJDWidth - 46*2;
        CGFloat phoneH = 40;
        self.phoneField.frame = CGRectMake(phoneX, phoneY, phoneW, phoneH);

        CGFloat viewX = 46 ;
        CGFloat viewY = CGRectGetMaxY(self.phoneField.frame);
        CGFloat viewW = phoneW;
        CGFloat viewH = 1;
        self.viewPhone.frame = CGRectMake(viewX,viewY, viewW, viewH);
        
        CGFloat passwordX = 46  ;
        CGFloat passwordY = CGRectGetMaxY(self.phoneField.frame) + HJDVerticalMargin;
        CGFloat passwordW = phoneW;
        CGFloat passwordH = phoneH;
        self.passwordtextField.frame = CGRectMake(passwordX, passwordY, passwordW, passwordH);

        CGFloat passwordviewX = 46 ;
        CGFloat passwordviewY = CGRectGetMaxY(self.passwordtextField.frame);
        CGFloat passwordviewW = phoneW;
        CGFloat passwordviewH = 1;
        self.viewPass.frame = CGRectMake(passwordviewX, passwordviewY, passwordviewW, passwordviewH);

       
    }completion:^(BOOL finished){
        
    }];
}


-(void)textPassChange
{
    NSRange _range = [self.passwordtextField.text rangeOfString:@" "];
    if (_range.location != NSNotFound) {
        [MBProgressHUD showError:@"不可输入空格，请重新输入"];
        
    }

}


-(void)setupBtn
{
    CGFloat registerX = HJDWidth/4-50/2;
    CGFloat registerY = CGRectGetMaxY(self.backgroundView.frame);
    CGFloat registerW = 40;
    CGFloat registerH = 50;
    UIButton *registerBtn = [[UIButton alloc]initWithFrame:CGRectMake(registerX, registerY, registerW, registerH)];
    registerBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [registerBtn setTitle:@"注册" forState:UIControlStateNormal];
    [registerBtn setTitleColor:[UIColor getColorWithHexNumber:@"BCBCBC"] forState:UIControlStateNormal];
    [registerBtn addTarget:self action:@selector(registerBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registerBtn];
//    竖线
    CGFloat viewX = HJDWidth/2 ;
    CGFloat viewY = CGRectGetMaxY(self.backgroundView.frame) + HJDVerticalMargin/2;
    CGFloat viewW = 1;
    CGFloat viewH = 30;
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(viewX, viewY, viewW, viewH)];
    view.backgroundColor = [UIColor getColorWithHexNumber:@"B3B3B3"];
    [self.view addSubview:view];
    
    CGFloat forgetX = CGRectGetMaxX(view.frame) + 48;
    CGFloat forgetY = CGRectGetMaxY(self.backgroundView.frame);
    CGFloat forgetW = 60;
    CGFloat forgetH = 50;
    UIButton *forgetBtn = [[UIButton alloc]initWithFrame:CGRectMake(forgetX, forgetY, forgetW, forgetH)];
    forgetBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [forgetBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
    [forgetBtn setTitleColor:[UIColor getColorWithHexNumber:@"FFA0A0"] forState:UIControlStateNormal];
    [forgetBtn addTarget:self action:@selector(forgetBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:forgetBtn];
    
}

#pragma mark - 保存图片至本地沙盒
-(void)saveImage:(UIImage *)currentImage Name:(NSString *)imageName{
    
    NSData * imageData = UIImageJPEGRepresentation(currentImage, 1);//1为不缩放保存，取值（0.0-1.0）
    //    获取沙盒目录
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
    //    将图片写入文件
    [imageData writeToFile:fullPath atomically:NO];
    
}

-(void)loginbtnClick
{
//    防止多次点击
    [[self class]cancelPreviousPerformRequestsWithTarget:self selector:@selector(todoBtn) object:nil];
    [self performSelector:@selector(todoBtn) withObject:nil afterDelay:0.2];
    
}


-(void)todoBtn
{
    NSRange _range = [self.passwordtextField.text rangeOfString:@" "];
    if (_range.location == NSNotFound) {
        NSString *phone = @"^1+[34578]+\\d{9}";
        NSPredicate *pr = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phone];
        if ([pr evaluateWithObject:self.phoneField.text ]) {
            if (self.phoneField.text.length == 11 ) {
                if (self.passwordtextField.text.length>0) {
                        NSString *registID = [[NSUserDefaults standardUserDefaults]stringForKey:@"RegistrationID"];
                    NSLog(@"regist%@",registID);
                    
                    NSString * url = @"/app/login.do";
                    NSString *path = [Hurl stringByAppendingString:url];
                    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
                    NSMutableDictionary *params = [NSMutableDictionary dictionary];
                    
                    NSString *strr = [self md5:self.passwordtextField.text];
                    NSLog(@"%@",strr);
                    
                    params[@"phone"] = self.phoneField.text;
                    params[@"password"] = strr;
                    if (registID == nil) {
                        params[@"registrationId"] = [NSString stringWithFormat:@"%s",""];
                    }else{
                    params[@"registrationId"]=registID;
                    }
                    
                    [mgr POST:path parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
                        
                    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                        
                        
                        NSDictionary *infoDicS = (NSDictionary *)responseObject;
                        
                        NSString *successfolStr = infoDicS[@"resultCode"];
                        
                        if ([successfolStr isEqualToString:@"001" ]) {
                            
                            
                            NSDictionary *infoDic = (NSDictionary *)responseObject;
                            NSString *heaeImage = infoDic[@"resultMap"][@"user"][@"headurl"];
                            NSData *Himg = [NSKeyedArchiver archivedDataWithRootObject:heaeImage];
                            [[NSUserDefaults standardUserDefaults]setValue:Himg forKey:@"headImage"];
                            
                            NSString *status = infoDic[@"resultMap"][@"status"];
                            NSUserDefaults *defaStatus = [NSUserDefaults standardUserDefaults];
                            [defaStatus setObject:status forKey:@"TypeStatus"];
                            [defaStatus synchronize];
                            
                            NSString *statusCase = infoDic[@"resultMap"][@"statusCase"];
                            NSUserDefaults *defaSC = [NSUserDefaults standardUserDefaults];
                            [defaSC setObject:statusCase forKey:@"stusCase"];
                            [defaSC synchronize];
                            
                            //
                            NSString *phone = infoDic[@"resultMap"][@"user"][@"phone"];
                            NSUserDefaults *phonede = [NSUserDefaults standardUserDefaults];
                            [phonede setObject:phone forKey:@"phonenum"];
                            [phonede synchronize];
                            
                            
                            NSString *name = infoDic[@"resultMap"][@"user"][@"name"];
                            NSData *nameDe = [NSKeyedArchiver archivedDataWithRootObject:name];
                            [[NSUserDefaults standardUserDefaults]setValue:nameDe forKey:@"nameD"];
                            
                            NSString *pregnancy = infoDic[@"resultMap"][@"user"][@"pregnancy"];
                            
                            NSUserDefaults *defaP = [NSUserDefaults standardUserDefaults];
                            [defaP setObject:pregnancy forKey:@"pregnanc"];
                            [defaP synchronize];
                            
                            NSString *dueDa = infoDic[@"resultMap"][@"user"][@"dueDate"];
                            NSData *dueDate = [NSKeyedArchiver archivedDataWithRootObject:dueDa];
                            [[NSUserDefaults standardUserDefaults]setValue:dueDate forKey:@"due"];
                            
                            NSString *syspre = infoDic[@"resultMap"][@"user"][@"sysPregnancy"];
                            NSData *syspreData = [NSKeyedArchiver archivedDataWithRootObject:syspre];
                            [[NSUserDefaults standardUserDefaults]setValue:syspreData forKey:@"sysPregnancy"];
                            
                            NSString *nickname = infoDic[@"resultMap"][@"user"][@"nickname"];
                            NSUserDefaults *nicknameDe = [NSUserDefaults standardUserDefaults];
                            [nicknameDe setObject:nickname forKey:@"changNick"];
                            [nicknameDe synchronize];
                            //
                            
                            NSString *qq = infoDic[@"resultMap"][@"user"][@"qq"];
                            
                            NSData *qqDe = [NSKeyedArchiver archivedDataWithRootObject:qq];
                            [[NSUserDefaults standardUserDefaults]setValue:qqDe forKey:@"qqD"];
                            
                            
                            NSString *Id = infoDic[@"resultMap"][@"user"][@"id"];
                            NSUserDefaults *idDe = [NSUserDefaults standardUserDefaults];
                            [idDe setObject:Id forKey:@"Id"];
                            [idDe synchronize];
                            NSString *uid = infoDic[@"resultMap"][@"user"][@"uid"];
                            NSUserDefaults *uidDe = [NSUserDefaults standardUserDefaults];
                            [uidDe setObject:uid forKey:@"uId"];
                            [uidDe synchronize];
                            
                            NSDictionary *infoDictionary = (NSDictionary *)responseObject;
                            NSString *info = infoDictionary[@"resultMap"];
                            NSData *dataS = [NSKeyedArchiver archivedDataWithRootObject:info];
                            [[NSUserDefaults standardUserDefaults] setValue:dataS forKey:@"userS"];
                            
                            
                            
                            
                            HJDTabBarController *tabBar = [[HJDTabBarController alloc]init];
                            HJDPesonalCenterViewController *personalVC = [[HJDPesonalCenterViewController alloc] init];
                            
                            RESideMenu *sideMenuViewController = [[RESideMenu alloc]initWithContentViewController: tabBar leftMenuViewController:personalVC  rightMenuViewController:nil];
                            
                            sideMenuViewController.backgroundImage = [UIImage imageNamed:@"bg"];
                            sideMenuViewController.menuPreferredStatusBarStyle = 1; // UIStatusBarStyleLightContent
                            sideMenuViewController.delegate = self;
                            sideMenuViewController.contentViewShadowColor = [UIColor blackColor];
                            sideMenuViewController.contentViewShadowOffset = CGSizeMake(0, 0);
                            sideMenuViewController.contentViewShadowOpacity = 0.2;
                            sideMenuViewController.contentViewShadowRadius = 12;
                            sideMenuViewController.contentViewShadowEnabled = YES;
                            
                            // 切换根控制器:可以直接把之前的根控制器清空
                            
                            HJDKeyWindow.rootViewController = sideMenuViewController;
                            
                            
                            [MBProgressHUD showSuccess:@"登录成功"];
                            
                            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                            NSDictionary * dic = @{@"phone":self.phoneField.text, @"password":self.passwordtextField.text};
                            [defaults setObject:dic forKey:@"userInfo"];
                            
                            [defaults synchronize];
                            
                            /**
                             *   用户headurl
                             */
                            
                            NSData *HeImg = [[NSUserDefaults standardUserDefaults]valueForKey:@"headImage"];
                            NSString *value = [NSKeyedUnarchiver unarchiveObjectWithData:HeImg];
                            
                            if (value != nil) {
                                
                                NSString *urlstring = [NSString stringWithFormat:@"%@/%@", headImageUrl,value];
                                
                                UIImage *savedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlstring]]];
                                
                                [self saveImage:savedImage Name:@"currentImage.png"];
                                
                            }
                        }
                        else if ( [successfolStr isEqualToString:@"002"])
                        {
                            [MBProgressHUD showError:@"密码或着账号不对"];
                        }else if ([successfolStr isEqualToString:@"006"]){
                            [MBProgressHUD showError:@"账号不存在"];
                        }else if ([successfolStr isEqualToString:@"999"]){
                            [MBProgressHUD showError:@"系统异常"];
                        }else{
                            [MBProgressHUD showError:@"服务器升级，请稍后再试"];
                        }
                        
//                        NSLog(@"yes'''''''''''%@",responseObject);
                        
                    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                        [MBProgressHUD showError:@"服务器升级，请稍后再试"];
                        NSLog(@"%@",error);
                    }];
                }else{
                    [MBProgressHUD showError:@"密码不可为空"];
                }
                
            }else{
                [MBProgressHUD showError:@"请正确输入手机号"];
            }
        }else{
            [MBProgressHUD showError:@"无效手机号"];
        }
    }else{
        [MBProgressHUD showError:@"密码有空格，请重新输入"];
        
    }

}


  


-(void)registerBtnClick
{
    HJDResigesViewController * registerVC = [[HJDResigesViewController alloc]init];
    HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:registerVC];

    [self presentViewController:nav animated:YES completion:nil];
//    
//    NSString *registID = [[NSUserDefaults standardUserDefaults]stringForKey:@"RegistrationID"];
//    NSLog(@"registID = %@",registID);

//    NSData *data3 = [[NSUserDefaults standardUserDefaults ]valueForKey:@"userS"];
//    NSString *info3 = [NSKeyedUnarchiver unarchiveObjectWithData:data3];
//    
//    NSLog(@"userS---------%@-----",info3);
//    
   
    
     }

-(void)forgetBtnClick
{
    HJDForgetViewController * forgetVC = [[HJDForgetViewController alloc]init];
    HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:forgetVC];
    
    [self presentViewController:nav animated:YES completion:nil];
}

@end
